﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProjectStore30032013.DAL;

namespace ProjectStore30032013.PRESENTATION
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }


        private void menu_Load (object sender, EventArgs e)
        {
            if (new Controler().TestConnection() == false)
                if (MessageBox.Show("System can't connect to database server, Do you want to config connection?", "Connection ERORR!", MessageBoxButtons.YesNo,MessageBoxIcon.Error) == DialogResult.Yes)
                    new FormConnectionToServer().ShowDialog(); 
        }

        private void LoadDefault()
        {
            toolStripConnection.Text = "Đang tìm kết nối!";
            toolStripConnection.Image = imageList.Images["iconConnected"];
        }
        private void btnCloseTab_Click(object sender, EventArgs e)
        {
            try
            {
                tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
            }
            catch
            {
            }
        }

        #region {timer event}
        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = Controler.timeOfProgram().ToString();
          
        }
        private void timerForConnection_Tick(object sender, EventArgs e)
        {
            if (new Controler().TestConnection() == true)
            {
                toolStripConnection.Text = "Đã kết nối!";
                toolStripConnection.Image = imageList.Images["iconConnected"];

            }
            else
            {
                toolStripConnection.Text = "Mất kết nối!";
                toolStripConnection.Image = imageList.Images["iconDisconnected"];
            }
        }
        #endregion 


        #region {event of menu}
        private void addTabControl(Form _frmFormNew)
        {
            TabPage _pageNew = new TabPage();
            _pageNew.Text = _frmFormNew.Text;
            _frmFormNew.TopLevel = false;
            _frmFormNew.Show();
            _frmFormNew.FormBorderStyle = FormBorderStyle.None;
            _frmFormNew.Dock = DockStyle.Bottom;
            _frmFormNew.Dock = DockStyle.Left;
            _pageNew.Controls.Add(_frmFormNew);
            this.tabControl1.TabPages.Add(_pageNew);
            tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1; 

        }
        private void qLHóaĐơnToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }
        private void cacácToolStripMenuItem_Click(object sender, EventArgs e)
        {
            REPORT.FormReportListProduct f = new REPORT.FormReportListProduct();
            f.ShowDialog();
            
        }
        private void kếtNốiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormConnectionToServer _frmConnection = new FormConnectionToServer();
            _frmConnection.Show(); 
        }   
        private void qLTàiKhoảnToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        private void danhMụcNhàCungCấpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addTabControl(new frm_Supplier());
        }
        private void danhMụcKháchHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addTabControl(new frmCustomer());
        }
        private void thêmTàiKhoảnToolStripMenuItem_Click(object sender, EventArgs e)
        {

            addTabControl(new frmAddUser());
        }
        private void hóaĐơnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.addTabControl(new frmExport());
        }
        private void danhMụcHàngHóaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addTabControl(new frmManageProduct());
        }
        private void hóaĐơnĐặtHàngToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            addTabControl(new frmExportBefore());
        }
        private void hóaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        private void qLDanhMụcToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        #endregion 

        private void tiềnTệToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addTabControl(new FormManagerMoneyUnit());
        }

      


    }
}
